#include "head.h"
//栈函数
bool isempty(stack1_t stack){
    return stack.stacksize==0;
}
int pop(stack1_t* stack,char* del_data){
    if(isempty(*stack)){
        return -1;
    }
    memcpy(del_data,stack->top->data,strlen(stack->top->data));

    stacknode_t* p=stack->top;
    stack->top=p->next;

    stack->stacksize--;
    if(stack->stacksize==0){
        stack->bottom=NULL;
    }
    free(p->data);
    free(p);
    return 0;
}
int push(stack1_t* stack,char* add_data){
    stacknode_t* s=(stacknode_t*)malloc(sizeof(stacknode_t));
    if(s==NULL){
        return -1;
    }
    s->data=(char*)malloc(sizeof(char)*(strlen(add_data)+1));
    memcpy(s->data,add_data,strlen(add_data));
    s->data[strlen(add_data)]='\0';
    s->next=stack->top;

    stack->stacksize++;
    stack->top=s;

    if(stack->stacksize==1){
        stack->bottom=s;
    }
    return 0;
}
int travel_stack(stack1_t stack,char* workingdir){
    char buf1[4096]={0};
    char target[8096]={0};
    stacknode_t* cur=stack.top;
    while(cur){
        sprintf(target,"%s/%s",cur->data,buf1);
        printf("stack1.c: %s\n",target);
        memcpy(buf1,target,strlen(target));
        cur=cur->next;
    }
    memcpy(workingdir,target,strlen(target));
    workingdir[strlen(target)]='\0';
    return 0;
}
void print_stack(stack1_t dir){
    stack1_t p=dir;
    for(int i=0;i<dir.stacksize;i++){
        printf("%s ",p.top->data);
        p.top=p.top->next;
    }
    printf("\n");
}
